package com.yingpai.fitness.dvp_2_0.main.util;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.yingpai.fitness.R;

/**
 * Created by ASUS on 2018/11/21.
 */

public class DialogUtil {
    private static DialogUtil dialogUtil = null;
    public View dialog_bottom_layout;
    public Dialog dialog_bottom;
    public View dialog_center_layout;
    public Dialog dialog_center;

    private DialogUtil(){}

    public static DialogUtil getInstance(){
        if(dialogUtil==null){
            dialogUtil = new DialogUtil();
        }
        return dialogUtil;
    }

    public void showBottomDialog(Context context, int layout){
        dialog_bottom_layout = View.inflate(context, layout, null);
        dialog_bottom = new Dialog(context, R.style.ShopDialogStyle);
        dialog_bottom.setContentView(dialog_bottom_layout);
        Window dialogWindow = dialog_bottom.getWindow();
        WindowManager m = dialogWindow.getWindowManager();
        Display d = m.getDefaultDisplay();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.x = 0;
        lp.y = 0;
//        lp.height = d.getHeight();
        lp.width = d.getWidth();
        // 设置显示位置
        dialog_bottom.onWindowAttributesChanged(lp);
        // 设置点击外围解散
        dialog_bottom.setCanceledOnTouchOutside(true);
        dialog_bottom.show();
    }

    public void showCenterDialog(Context context, int layout){
        dialog_center_layout = View.inflate(context,layout, null);
        dialog_center = new AlertDialog.Builder(context, R.style.NoBackGroundDialog).create();
        dialog_center.show();
        dialog_center.setContentView(dialog_center_layout);
    }
}
